package tp.pr4;


public class City {
	Street[] cityMap;
	/**
	 * 	Creates a city using an array of streets
	 * @param cityMap
	 */
	public City(Street[] cityMap) {
		this.cityMap = cityMap;
	}
	/**
	 * Default constructor
	 */
	public City() {
		this.cityMap = new Street[0];
	}
	/**
	 * Looks for the street that starts from the given place in the given direction. 
	 * @param currentPlace
	 * @param currentHeading
	 * @return
	 */
	public Street lookForStreet(Place currentPlace, Direction currentHeading){
		for(Street st : this.cityMap){
			if(st.comeOutFrom(currentPlace, currentHeading)){
				return st;
			}
		}
		return null;
	} 
	/**
	 * Adds a street to the city;
	 * @param street
	 */
	public void addStreet(Street street){
		int n = this.cityMap.length;
		Street v[] = new Street[n+1];
		for(int i=0; i<n; i++){
			v[i] = cityMap[i];
		}
		v[n] = street;
		this.cityMap = v;
	}
	
	/**
	 * Returns the city streetmap
	 */
	public Street[] getCityMap(){
		return this.cityMap;
	}
	
	/**
	 * Returns the initialPlace
	 */
	public Place getInitialPlace(){
		return cityMap[0].getSource();
	}

}
